// compile: g++ -o thread_pool thread_pool.cc -std=c++17
// run: ./thread_pool
#include <atomic>
#include <chrono>
#include <string>

#include "thread_pool.h"
using namespace std;

class MyTask : public Task {
 public:
  Any Run() override;
};
Any MyTask::Run() {
  std::cout << "thread " << std::this_thread::get_id() << " begin" << std::endl;
  std::this_thread::sleep_for(std::chrono::seconds(2s));
  std::cout << "thread " << std::this_thread::get_id() << " end" << std::endl;
  return 42;
}

void Test1() {
  ThreadPool pool(MODE::CACHED);
  pool.SetThreadNum(3);
  pool.Start();

  pool.AddTask(std::make_shared<MyTask>());

  cin.get();
}
void Test2() {
  ThreadPool pool(MODE::CACHED);
  pool.SetThreadNum(3);
  pool.Start();
  Result res = pool.AddTask(std::make_shared<MyTask>());
  int a = res.Get().Cast<int>();
  std::this_thread::sleep_for(std::chrono::seconds(6));
  cout << "1" << endl;
  cout << "a=" << a << endl;
}
Any Test3() { return 3.9; }
int main() {
  Test1();
  // Test2();
  // cout << Test3().Cast<double>() << endl;

  return 0;
}
